package com.dongxing.concyrrency.chapter4;

import java.util.concurrent.TimeUnit;

/**
 * @author XavierDong
 **/
public class DaemonThread {

    public static void main(String[] args) {

        System.out.println(10_000);

        Thread t1 = new Thread() {
            @Override
            public void run() {
                try {
                    System.out.println(Thread.currentThread().getName() + " running.");
                    TimeUnit.SECONDS.sleep(10);
                    System.out.println(Thread.currentThread().getName() + " done.");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    Thread.currentThread().interrupt();
                }
            }
        }; // new

        // 设置为守护线程
        t1.setDaemon(true);

        // runnable ----> running --->dead --->block
        t1.start();

        // JDK1.7
        try {
            Thread.sleep(5_000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(Thread.currentThread().getName());
    }
}
/**
 * A <-----------> B
 * <p>
 * -> daemonThread (health check)
 */